import 'package:flutter/material.dart';
import '../common/pay/wechat_pay_utils.dart';
import '../config/theme_color.dart';
import '../picture/walfare_add_page.dart';
import '../user/user_profile_page.dart';
import '../video/video_main_page.dart';
import 'home_page.dart';

class AppMainPage extends StatefulWidget {
  int currentIndex = 0;

  AppMainPage({this.currentIndex = 0, super.key});

  @override
  State<AppMainPage> createState() => _AppMainPageState();
}

class _AppMainPageState extends State<AppMainPage> {
  int _bottomNavIndex = 0;
  final _checkColor = ThemeColor.mainColor;
  final _normalColor = ThemeColor.textColor;
  List<String> titleList = [
    '首页',
    '福利',
    '视频',
    '我的',
  ];
  List<Icon> iconList = [
    const Icon(Icons.home),
    const Icon(Icons.wallet_giftcard),
    const Icon(Icons.video_camera_back_outlined),
    const Icon(Icons.person),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: IndexedStack(
        index: _bottomNavIndex,
        children: const [
          HomePage(),
          WelfareAddPage(),
          VideoMainPage(),
          UserProfilePage(),
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _bottomNavIndex,
        onTap: (int index) {
          setState(() {
            _bottomNavIndex = index;
          });
        },
        type: BottomNavigationBarType.fixed,
        selectedIconTheme: IconThemeData(color: _checkColor),
        unselectedIconTheme: IconThemeData(color: _normalColor),
        selectedItemColor: _checkColor,
        unselectedItemColor: _normalColor,
        selectedFontSize: 12,
        unselectedFontSize: 12,
        items: [
          _buildTabs(icon: iconList.first, titleStr: titleList.first),
          _buildTabs(icon: iconList[1], titleStr: titleList[1]),
          _buildTabs(icon: iconList[2], titleStr: titleList[2]),
          _buildTabs(icon: iconList.last, titleStr: titleList.last),
        ],
      ),
    );
  }

  BottomNavigationBarItem _buildTabs(
      {required Icon icon, required String titleStr}) {
    return BottomNavigationBarItem(
      icon: icon,
      label: titleStr,
    );
  }

  @override
  void initState() {
    super.initState();
    _bottomNavIndex = widget.currentIndex;
    WechatPayUtils().initFlutterWX();
  }
}
